package com.cyj.spring.springframeword.beans.test.beans;

/**
 * @Description: 不同利率下的投资增长情况
 * @BelongsProject: small-spring
 * @BelongsPackage: com.cyj.spring.springframeword.beans.test.beans
 * @Author: ChenYongJia
 * @CreateTime: 2021-07-28 16:04
 * @Email: chen87647213@163.com
 * @Version: 1.0
 */
public class CompoundInterest {

    /**
     * 用简单的程序模拟 多维数组 实现
     *
     * @param args
     * @return void
     * @date 2021/7/28 16:04
     * @author ChenYongJia
     * @version 1.0
     */
    public static void main(String[] args) {

        /**
         * 初始利率
         */
        final double START_RATE = 10;

        /**
         * 利率
         */
        final int N_RATES = 11;

        /**
         * 年
         */
        final int N_YEARS = 10;

        // 设置 interest Rate 利率 10-20
        double[] interestRate = new double[N_RATES];
        for (int i = 0; i < interestRate.length; i++)
            interestRate[i] = (START_RATE + i) / 100.0;

        // 设置余额 50000
        double[][] balances = new double[N_YEARS][N_RATES];
        for (int i = 0; i < balances[0].length; i++)
            // 表示第一年的余额是五万
            balances[0][i] = 50000;

        // 计算未来几年的利息
        for (int i = 1; i < balances.length; i++) {
            for (int j = 0; j < balances[i].length; j++) {

                // 得到去年的余额
                double oldBalances = balances[i - 1][j];

                // 计算利息
                double interest = balances[i - 1][j];

                // 计算今年的余额
                balances[i][j] = oldBalances + interest;
            }
        }

        // 制表头
        System.out.println("\t\t\t\t\t\t\t\t\t\t\t\t\t不同利率下的增长情况");

        // 制表
        System.out.println("——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————");

        // 打印利率
        for (int i = 0; i < interestRate.length; i++)
            System.out.printf("%9.0f%%\t", 100 * interestRate[i]);

        System.out.println();

        // 输出金额表格
        for (double[] row : balances) {
            // 输出每一行
            for (double r : row)
                System.out.printf("%10.2f\t", r);
            System.out.println();
        }
    }

}
